package com.example.musicproject_b.Controller;

import com.example.common.b_pojo.BRole;
import com.example.common.utils.Resultb;
import com.example.service.BRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/B_admin/adminroles")
public class AdminRolesController {

    @Autowired
    private BRoleService bRoleService;

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:15
     * 角色列表(全部不包含逻辑删除)
     */
    @RequestMapping("/alllist")
    public Resultb alllist(int pageNum, int pageSize) {
        return Resultb.success(bRoleService.alllist(pageNum, pageSize));
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:15
     * 角色列表(包含逻辑删除)
     */
    @RequestMapping("/hasdelectlist")
    public Resultb hasdelectlist(int pageNum, int pageSize) {
        return Resultb.success(bRoleService.hasdelectlist(pageNum, pageSize));
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/4 15:30
     * 根据id查询记录
     */
    @RequestMapping("/getrole")
    public Resultb getrole(Long id) {
        return Resultb.success(bRoleService.getrole(id));
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:16
     *  修改角色(包含逻辑删除)
     */
    @RequestMapping("/updaterole")
    public Resultb updaterole(@RequestBody BRole bRole) {
        if (bRoleService.updateRole(bRole)){
            return Resultb.success("修改成功");
        }else {
            return Resultb.error();
        }
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:25
     *  禁用删除角色
     */
    @RequestMapping("/deleterole")
    public Resultb deleterole(Long id) {
        if (bRoleService.deleteRole(id)){
            return Resultb.success("删除成功");
        }else {
            return Resultb.error();
        }
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/9 16:43
     * 启用角色
     */
    @RequestMapping("/startrole")
    public Resultb startroleroleid(Long id) {
        boolean b = bRoleService.startRoleByRoleId(id);
        if (b){
            return Resultb.success("启用成功");
        }else {
            return Resultb.error();
        }
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:26
     * 增加角色
     */
    @RequestMapping("/insertrole")
    public Resultb insertrole(@RequestBody BRole bRole) {
        if (bRoleService.insertRole(bRole)){
            return Resultb.success("添加成功");
        }else {
            return Resultb.error();
        }
    }



    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:26
     * 添加角色权限
     */
    @RequestMapping("/addrolepermission")
    public Resultb addrolepermission(Long roleId, Long PermisionId) {
        if (bRoleService.insertRoleandPermission(roleId, PermisionId)){
            return Resultb.success("添加成功");
        }else {
            return Resultb.error();
        }
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/8/23 11:26
     * 删除角色权限
     */
    @RequestMapping("/deleterolepermission")
    public Resultb deleterolepermission(Long roleId, Long PermisionId) {
        if (bRoleService.delectRoleandPermission(roleId, PermisionId)){
            return Resultb.success("删除成功");
        }else {
            return Resultb.error();
        }
    }

}
